import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class IconLabelButton extends StatelessWidget {
  final String imagePath; // 图片资源路径
  final String label; // 文字内容
  final double iconSize; // 图标尺寸（统一宽高）
  final double textSize; // 文字大小
  final Color textColor; // 文字颜色
  final VoidCallback? onTap; // 点击回调
  final Axis layoutDirection; // 布局方向（默认垂直）
  final double spacing; // 图文间距

  const IconLabelButton({
    super.key,
    required this.imagePath,
    required this.label,
    this.iconSize = 36,
    this.textSize = 14,
    this.textColor = Colors.black,
    this.onTap,
    this.layoutDirection = Axis.vertical,
    this.spacing = 8,
  });

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      borderRadius: BorderRadius.circular(4.w), // 添加点击圆角
      child: Padding(
        padding: EdgeInsets.all(4.w), // 增加点击区域
        child: _buildContent(),
      ),
    );
  }

  Widget _buildContent() {
    // 共用组件
    final icon = Image.asset(imagePath, width: iconSize.w, height: iconSize.w);

    final text = Text(
      label,
      style: TextStyle(
        fontSize: textSize.r,
        color: textColor,
        fontWeight: FontWeight.normal,
      ),
    );

    // 根据方向返回不同布局
    return layoutDirection == Axis.vertical
        ? Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              icon,
              SizedBox(height: spacing.w),
              text,
            ],
          )
        : Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              icon,
              SizedBox(width: spacing.w),
              text,
            ],
          );
  }
}
